package com.example.service;

import com.example.entity.Comment;
import com.example.repository.CommentRepository;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {

    @Autowired
    CommentRepository commentRepository;
    //查询所有数据
    public List<Comment> selectCommentAll(){
        return commentRepository.findAll();
    }

    //通过查询AId数据
    public List<Comment> selectByAId(Integer aId){
        return commentRepository.selectByAId(aId);
    }

    //添加数据
    public void addComment(String author,String content,Integer aId){
        Comment comment = new Comment();
        comment.setAId(aId);
        comment.setAuthor(author);
        comment.setContent(content);
        commentRepository.save(comment);
    }
}
